//
//  ZYLFindFrontSigleLayout.m
//  Cartoon
//
//  Created by dllo on 15/7/15.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "ZYLFindFrontSigleLayout.h"
#import "Define.h"
@implementation ZYLFindFrontSigleLayout


//-(CGSize)collectionViewContentSize
//{
//    return CGSizeMake(SCREEN_WIDTH, (SCREEN_HEIGHT / 4.0 + 5) * 5);
//}
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
    CGFloat x = (indexPath.item % 2) * (SCREEN_WIDTH / 2.0) + (SCREEN_WIDTH / 4.0);
    CGFloat y = (((indexPath.item - 1) / 2) * (SCREEN_HEIGHT / 4.0 + 5)) + (5 + (SCREEN_HEIGHT / 4.0) / 2) + 55 * ((indexPath.item + 1) % 2);
    if (indexPath.item == 0) {
        attributes.center = CGPointMake(x, 30);
        attributes.size = CGSizeMake(SCREEN_WIDTH / 2.0 - 5, 50);
    }else if (indexPath.item == [self.collectionView numberOfItemsInSection:0] - 1) {
        attributes.center = CGPointMake(x, y - (((SCREEN_HEIGHT / 4.0 + 5) / 4.0)) - 15);
        attributes.size = CGSizeMake(SCREEN_WIDTH / 2.0 - 5, 50);
    } else {
        attributes.center = CGPointMake(x, y);
        attributes.size = CGSizeMake(SCREEN_WIDTH / 2.0 - 5, (SCREEN_HEIGHT / 4.0));
    }
    return attributes;
}

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
    NSArray *arr = [super layoutAttributesForElementsInRect:rect];
    if (arr.count > 0) {
        return arr;
    }
    NSMutableArray *attArr = [NSMutableArray array];
    for (NSInteger i = 0 ; i < [self.collectionView numberOfItemsInSection:0]; i++) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0];
        [attArr addObject:[self layoutAttributesForItemAtIndexPath:indexPath]];
    }
    return attArr;
}

- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)oldBounds
{
    return YES;
}
@end
